﻿using System;
using System.Collections.Generic;
using System.Data;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Gift.Model.ENUM;

namespace WebSite.admin.order
{
    public partial class orderComplainTypeList : BaseAdmin
    {

        // Methods
        private void AddPicture(string str)
        {
            SQLAccess.DoSql("insert into tbCompain(CompainName,companyId) values('" + str.ToString() + "'," + base.Administrator.CompanyId + ")");
        }

   
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.ValidateLoginRule(ERule.OrderComplainType);
                this.upbind();
            }
        }

        private void upbind()
        {
            string sql = "select * from tbCompain";
            DataSet set = SQLAccess.GreatDs(sql);
            this.DataList1.DataSource = set;
            this.DataList1.DataBind();
            if ((base.Request.QueryString["mid"] != null) && (base.Request.QueryString["action"] != null))
            {
                if (base.Request.QueryString["action"].ToString() == "del")
                {
                    SQLAccess.DoSql("delete from tbCompain where CompainId=" + base.Request.QueryString["mid"].ToString() + "");
                }
                base.Response.Write("<script language='javascript'>window.location.href='orderComplainTypeList.aspx';</script>");
                base.Response.End();
            }
        }

        private void upcontent()
        {
            string sql = string.Format("select * from tbCompain where companyId = {0} order by CompainId asc",base.Administrator.CompanyId);
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            if (table.Rows.Count > 0)
            {
                foreach (DataRow row in table.Rows)
                {
                    SQLAccess.DoSql("update tbCompain set [CompainName]='" + base.Request.Form["content_" + row["CompainId"].ToString()] + "' where CompainId=" + row["CompainId"].ToString() + "");
                }
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string[] strArray = base.Request.Form["text"].Split(new char[] { ',' });
            this.upcontent();
            for (int i = 0; i < strArray.Length; i++)
            {
                if (strArray[i].ToString() != "")
                {
                    this.AddPicture(strArray[i]);
                }
            }
            base.Response.Write("<script language='javascript'>alert('更新成功');window.location.href='orderComplainTypeList.aspx';</script>");
            base.Response.End();
        }


    }
}